package com.movie.controller;

import com.movie.dto.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/statistics")
@RequiredArgsConstructor
@Tag(name = "数据统计", description = "系统数据统计接口")
public class StatisticsController {
    
    private final com.movie.service.StatisticsService statisticsService;
    
    @GetMapping("/dashboard/stats")
    @Operation(summary = "获取仪表板统计数据", description = "获取仪表板显示的核心统计数据")
    public ApiResponse<Map<String, Object>> getDashboardStats() {
        Map<String, Object> stats = statisticsService.getDashboardStats();
        return ApiResponse.success(stats);
    }
    
    @GetMapping("/user-growth")
    @Operation(summary = "获取用户增长数据", description = "获取用户增长趋势数据")
    public ApiResponse<Map<String, Object>> getUserGrowth(
            @Parameter(description = "时间范围") @RequestParam(required = false) String period) {
        Map<String, Object> result = statisticsService.getUserGrowth(period);
        return ApiResponse.success(result);
    }
    
    @GetMapping("/movies")
    @Operation(summary = "获取影片统计", description = "获取影片相关的统计数据")
    public ApiResponse<Map<String, Object>> getMovieStatistics(
            @Parameter(description = "查询参数") @RequestParam(required = false) Map<String, String> params) {
        Map<String, Object> result = statisticsService.getMovieStatistics(params == null ? java.util.Collections.emptyMap() : params);
        return ApiResponse.success(result);
    }
    
    @GetMapping("/comments")
    @Operation(summary = "获取评论统计", description = "获取评论相关的统计数据")
    public ApiResponse<Map<String, Object>> getCommentStatistics(
            @Parameter(description = "查询参数") @RequestParam(required = false) Map<String, String> params) {
        Map<String, Object> result = statisticsService.getCommentStatistics(params == null ? java.util.Collections.emptyMap() : params);
        return ApiResponse.success(result);
    }
    
    @GetMapping("/system-usage")
    @Operation(summary = "获取系统使用情况", description = "获取系统资源使用情况")
    public ApiResponse<Map<String, Object>> getSystemUsage() {
        Map<String, Object> result = statisticsService.getSystemUsage();
        return ApiResponse.success(result);
    }
    
    @GetMapping("/popular-movies")
    @Operation(summary = "获取热门影片", description = "获取热门影片列表")
    public ApiResponse<Map<String, Object>> getPopularMovies(
            @Parameter(description = "查询参数") @RequestParam(required = false) Map<String, String> params) {
        Map<String, Object> result = statisticsService.getPopularMovies(params == null ? java.util.Collections.emptyMap() : params);
        return ApiResponse.success(result);
    }
    
    @GetMapping("/active-users")
    @Operation(summary = "获取活跃用户", description = "获取活跃用户列表")
    public ApiResponse<Map<String, Object>> getActiveUsers(
            @Parameter(description = "查询参数") @RequestParam(required = false) Map<String, String> params) {
        Map<String, Object> result = statisticsService.getActiveUsers(params == null ? java.util.Collections.emptyMap() : params);
        return ApiResponse.success(result);
    }
}